#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;


 // Definition for a binary tree node.
  struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  };
 
class Solution {
public:
    vector<int> levelOrder(TreeNode* root) {
        vector<int> result;
        if(root==NULL){
            return result;
        }
        queue<TreeNode*> Q;
        Q.push(root);
        while(!Q.empty()){
            result.push_back(Q.front()->val);
            if(Q.front()->left!=NULL)
                Q.push(Q.front()->left);
            if(Q.front()->right!=NULL)
                Q.push(Q.front()->right);
            Q.pop();
        }
        return result;
    }
};